using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Comteck.Winforms.Controls.Loading {
  /// <summary>
  /// ajax提示框,这里不采用provider
  /// </summary>
  public class AjaxLoadHelper {

    /// <summary>
    /// 鼠标形式展示
    /// </summary>
    private readonly IAjaxLoadCommand ajaxLoadCursor;
    private readonly IAjaxLoadCommand ajaxLoadControl;

    /// <summary>
    /// ctor
    /// </summary>
    /// <param name="form"></param>
    public AjaxLoadHelper(Form form) {
      ajaxLoadCursor = new AjaxLoadCursor(form);
      ajaxLoadControl = new AjaxLoadControl(form);
    }

    /// <summary>
    /// 
    /// </summary>
    public bool IsWork() {
      return this.IsWork(AjaxLoadType.Cursor);
    }

    /// <summary>
    /// 
    /// </summary>
    public bool IsWork(AjaxLoadType type) {
      var isWork = false;

      switch (type) {
        case AjaxLoadType.Cursor:
          isWork = ajaxLoadCursor.IsWork;
          break;
        case AjaxLoadType.Shadow:
          isWork = ajaxLoadControl.IsWork;
          break;
        default:
          break;
      }

      return isWork;
    }

    /// <summary>
    /// 显示
    /// </summary>
    public IDisposable Show() {
      return this.Show(true);
    }

    /// <summary>
    /// 显示
    /// </summary>
    /// <param name="isPrevent">是否阻止，如果是，则不允许多次点击</param>
    public IDisposable Show(bool isPrevent) {
      return this.Show(AjaxLoadType.Cursor, isPrevent);
    }

    /// <summary>
    /// 提示
    /// </summary>
    /// <param name="type"></param>
    /// <param name="isPrevent">是否阻止，如果是，则不允许多次点击</param>
    public IDisposable Show(AjaxLoadType type, bool isPrevent) {
      switch (type) {
        case AjaxLoadType.Cursor:
          return ajaxLoadCursor.ShowAjax(isPrevent);
        case AjaxLoadType.Shadow:
          return ajaxLoadControl.ShowAjax(isPrevent);
        default:
          throw new NotSupportedException("不支持的枚举项");
      }
    }

    /// <summary>
    /// 隐藏
    /// </summary>
    public void Hide() {
      this.Hide(AjaxLoadType.Cursor);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="type"></param>
    public void Hide(AjaxLoadType type) {
      switch (type) {
        case AjaxLoadType.Cursor:
          ajaxLoadCursor.HideAjax();
          break;
        case AjaxLoadType.Shadow:
          ajaxLoadControl.HideAjax();
          break;
      }
    }

  }
}
